/*********************************************************
          File Name:global.h
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Fri 24 Apr 2015 11:05:22 PM CST
**********************************************************/

#ifndef GLOBAL_H_
#define GLOBAL_H_

#include <unistd.h>
#include <ev.h>

#define CONF_FILE_PATH      "/etc/pisces/pisces.conf"
#define LOG_FILE_PATH       "/var/log/pisces/pisces.log"
#define MIME_PATH           "/etc/pisces/pisces.mime"
#define PID_FILE            "/etc/pisces/pisces.pid"

#define CHILD_NUM           4   /* workprocess num */
#define LOG_FAILED          -1
#define LOG_SUCCESS         0

#define P_LOG_IFO             0
#define P_LOG_ERR             2
#define P_LOG_ALT             4
#define CONF_NUM              5 /* avaliable configurations */

#define MAX_EVENTS            1 /* maximum notification events */

typedef struct list {
    char *item;
    struct list *pre, *next;
    int index;
    off_t st_size;
    long mtime;
} pisces_dlist_t;

typedef struct {
    char *root_dir;
    char *cgi_dir;
    int backlog;
    char *port;
    char *host;
    char *log_fie;
} pisces_conf_t;

typedef struct {
    int timeout;
    pid_t child;
    int confd;
    unsigned int re_make:1;
} pisces_child_t;

typedef struct {
    int listenfd;
    int child_index;
    pisces_conf_t *conf;
    struct ev_loop *loop;
    pisces_child_t ch[CHILD_NUM];
    unsigned int exit:1;        /* if exit = 1, exit master */
} pisces_ctx_t;  

typedef struct {
    pisces_ctx_t arg;
    int child_id;
    int events_id;
} pisces_thread_arg_t;

#endif
